﻿
using System;
using System.Collections.Generic;
using System.Data;
using QLKS.Entity;

namespace QLKS.DAL
{
    public class DMLoaiPhongDAO
    {
         private SqlDataProvider dataProvider;

         public DMLoaiPhongDAO()
        {
            dataProvider = new SqlDataProvider();
        }

        public List<DMLoaiPhong> GetByAll(DMLoaiPhong obj)
        {
            List<DMLoaiPhong> lstData = new List<DMLoaiPhong>();;
            try
            {
                DataTable dt = dataProvider.ExecuteDataTable("sp_DMLoaiPhong_GetByAll"
                    , new string[] { "MaLoaiPhong", "TenLoaiPhong", "DonGia", "GhiChu" }
                    , new object[] { obj.MaLoaiPhong, obj.TenLoaiPhong, obj.DonGia, obj.GhiChu }
                );
                DMLoaiPhong entity;
                foreach(DataRow myrow in dt.Rows)
                {
                    entity = new DMLoaiPhong();
                    entity.MaLoaiPhong = Convert.ToInt32(myrow["MaLoaiPhong"]);
                    entity.TenLoaiPhong = myrow["TenLoaiPhong"] is DBNull ? string.Empty : myrow["TenLoaiPhong"].ToString();
                    entity.DonGia = Convert.ToDouble(myrow["DonGia"].ToString());
                    entity.GhiChu = myrow["GhiChu"] is DBNull ? string.Empty : myrow["GhiChu"].ToString();
                    lstData.Add(entity);
                }
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return lstData;
        }

        public bool Insert(DMLoaiPhong obj)
        {
            int i = dataProvider.ExecuteNonQuery("sp_DMLoaiPhong_Insert"
                    , new string[] { "MaLoaiPhong", "TenLoaiPhong", "DonGia", "GhiChu" }
                    , new object[] { obj.MaLoaiPhong, obj.TenLoaiPhong, obj.DonGia, obj.GhiChu }
                );
            return i == 1 ? true : false;
        }

        public bool Update(DMLoaiPhong obj)
        {
            int i = dataProvider.ExecuteNonQuery("sp_DMLoaiPhong_Update"
                    , new string[] { "MaLoaiPhong", "TenLoaiPhong", "DonGia", "GhiChu" }
                    , new object[] { obj.MaLoaiPhong, obj.TenLoaiPhong, obj.DonGia, obj.GhiChu }
                );
            return i == 1 ? true : false;
        }

        public bool Delete(DMLoaiPhong obj)
        {
            int i = dataProvider.ExecuteNonQuery("sp_DMLoaiPhong_Delete"
                    , new string[] { "MaLoaiPhong", "TenLoaiPhong", "DonGia", "GhiChu" }
                    , new object[] { obj.MaLoaiPhong, obj.TenLoaiPhong, obj.DonGia, obj.GhiChu }
                );
            return i == 1 ? true : false;
        }
    }
}
